const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}


/**
 * 获取当前时间 对象形式返回
 */
function getDate(){
  let timestamp = Date.parse(new Date());
  var date = new Date(timestamp);  
  const hour = date.getHours()
  const minute = date.getMinutes()



  //月  
  var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);  
  
  //日  
  var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();  

  var H = (hour  < 10 ? '0' :hour);  

  let result = {}
  result.date = `${date.getFullYear()}-${M} - ${D}`
  result.time = `${H}:${M}`
  return result
}

module.exports = {
  formatTime: formatTime,
  getDate:getDate
}
